package com.example.demo01.service.impl;

import com.example.demo01.controller.dto.LoginDto;
import com.example.demo01.controller.request.LoginRequest;
import com.example.demo01.entity.User;
import com.example.demo01.mapper.UserMapper;
import com.example.demo01.service.IUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService implements IUserService {

    @Autowired
    UserMapper userMapper;


    @Override
    public List<User> listUser() {
        return userMapper.listUser();
    }

    @Override
    public LoginDto login(LoginRequest request) {
        User user = userMapper.getByUsernameAndPassword(request);
        LoginDto loginDto = new LoginDto();
        BeanUtils.copyProperties(user,loginDto);
        return loginDto;
    }
}
